package com.作业.第八章作业.HomeWork01;

public class work01 {
    public static void main(String[] args) {
        person arr[] = new person[3];
        arr[0] = new person("张三", 118, "程序员");
        arr[1] = new person("李四", 20, "棋手");
        arr[2] = new person("王五", 320, "老师");

//118 20 320  118 320 20
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j].getAge() < arr[j + 1].getAge()) {
                    person temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].toString());
        }



    }
}
//1 2 3  2  3 4  1  5


class person {
    private String name;
    private int age;
    private String job;

    public person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getJob() {
        return job;
    }

    @Override
    public String toString() {
        return "person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }
}
/**
 * 1.定义一个person类，描述人的信息，包括姓名，年龄，工作。
 * 2.创建三个person对象并赋值；
 * 3.把person对象放入数组中，并按照age大小排序。
 */